package com.novellotus.iov.carvice.view;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;

/**
 * Created by Rich on 2017/8/16.
 */

public class TipsDialog extends Dialog {

    private ClickTipsInterface clickTipsInterface;
    private Context context;

    public TipsDialog(@NonNull Context context) {
        super(context, R.style.tips_dialog);
        this.context = context;
    }

    public TipsDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, R.style.tips_dialog);
    }

    public Button button;
    public ImageView img_cancel;

    public void initDialog(String tittle, String des, final ClickTipsInterface clickTipsInterface) {
        this.clickTipsInterface = clickTipsInterface;
        View view = LayoutInflater.from(context).inflate(R.layout.layout_tips_cancel, null);
        TextView tv_tittle = view.findViewById(R.id.tv_tips_tittle);
        TextView tv_des = view.findViewById(R.id.tv_des);
        img_cancel = view.findViewById(R.id.img_cancel);
        button = view.findViewById(R.id.btn_tips);
        tv_tittle.setText(tittle);
        tv_des.setText(des);
        img_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clickTipsInterface.clickTipsButton();
            }
        });
        getWindow().setBackgroundDrawableResource(android.R.color.transparent); //设置对话框背景透明 ，对于AlertDialog 就不管用了
        setCanceledOnTouchOutside(false);
        setContentView(view);
    }

    /**
     * 还原按钮状态
     */
    public void reSetButton() {
        button.setClickable(true);
        button.setText("确定");
    }


    public interface ClickTipsInterface {
        void clickTipsButton();
    }

}
